<!-- 单位抽签页面 -->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="项目名称" prop="extractItem">
        <el-input
          v-model="queryParams.extractItem"
          placeholder="请输入项目名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抽取人单位" prop="createBy">
        <el-select
          v-model="form.createBy"
          placeholder="请选择抽取人单位"
          clearable
          size="small"
          style="width: 100%"
          @change="UnitTypeChangepenson"
        >
          <el-option
            v-for="type in unitTypeponsonOptions"
            :key="type.userId"
            :label="type.nickName"
            :value="type.userId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="抽取库" prop="randomUnittypeId">
        <el-select
          v-model="form.randomUnittypeId"
          placeholder="请选择单位库"
          clearable
          size="small"
          style="width: 100%"
          @change="UnitTypeChange"
        >
          <el-option
            v-for="type in unitTypeOptions"
            :key="type.unittypeId"
            :label="type.unittypeName"
            :value="type.unittypeId"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="extractList"
      @selection-change="handleSelectionChange"
      @current-change="currentRowChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目名称" align="left" prop="extractItem" />
      <el-table-column label="建设地址" align="left" prop="extractAddress" />
      <el-table-column
        label="抽取人单位"
        align="left"
        prop="createBy"
        width="250"
      />
      <el-table-column label="工程费用（万元）" align="left" prop="extractPrice" />
      <el-table-column label="中介机构服务费（万元）" align="left" prop="maxPrice" />
      <el-table-column label="抽取库" align="left" prop="unitTypeName" />
      <el-table-column
        label="审批状态"
        align="center"
        prop="extractApproveStatus"
        :formatter="approveStatusFormat"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="260"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['unit:extract:edit']"
            v-if="scope.row.extractApproveStatus == 2"
          >
            抽取单位
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-refresh"
            @click="reback(scope.row)"
            v-hasPermi="['unit:extract:edit']"
            v-if="
              (scope.row.extractApproveStatus == 4) |
                (scope.row.extractApproveStatus == 7)
            "
          >
            重置结果
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="resultShow(scope.row)"
            v-if="scope.row.extractApproveStatus != 2"
          >
            结果打印
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="extractionComplete(scope.row)"
            v-hasPermi="['unit:extract:edit']"
            v-if="scope.row.extractApproveStatus == 4"
          >
            抽取完成
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      @current-change="currentChange"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目申请对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
      :close-on-click-modal="false"
      @close="closeTablebig"
    >
      <quotationConfirm
        class="quotationConfirm"
        :quotationConfirm="quotationConfirm"
      ></quotationConfirm>
      <!--用户输入内容-->
      <el-form
        :model="ruleForm"
        :rules="userRules"
        ref="ruleForm"
        label-width="150px"
        class="demo-ruleForm"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="抽取人" prop="extractUser">
              <el-input
                class="commonWidth"
                v-model="ruleForm.extractUser"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="抽取地点" prop="extractPlace"
              ><el-input
                class="commonWidth"
                v-model="ruleForm.extractPlace"
              ></el-input
            ></el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 库下对应单位表格 -->
      <template>
        <el-row v-if="unittype!='15'">
          <el-table
            v-loading="loading"
            id="unitTable"
            :data="unitList"
            max-height="400"
            :row-style="rowStyle"
          >
            <el-table-column
              label="序号"
              align="center"
              prop="unitSort"
              width="100"
            />
            <el-table-column
              label="单位名称"
              align="left"
              prop="unitName"
              width="310"
            />
            <el-table-column
              label="资质"
              align="center"
              prop="unitNaturalGrade"
              width="150"
              v-if="showmake"
            />
            <!-- <el-table-column label="手动排除" align="center" prop="extractPrice" :formatter="ManualApproveStatusFormat" width="120"/> -->
            <el-table-column
              label="是否选择"
              align="center"
              prop="isTick"
              :formatter="AutomaticApproveStatusFormat"
              width="120"
            />
            <el-table-column
              label="未选择理由"
              align="center"
              prop="notWonReason"
              width="120"
            />
            <el-table-column
              label="操作"
              align="center"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <!-- <el-button size="mini" type="text" icon="el-icon-circle-close" @click="overcome(scope.row)" v-if="scope.row.unitStatues == 0">禁用</el-button> -->
                <!-- <el-button size="mini" type="text" icon="el-icon-refresh-right" @click="DeleteMappingBtn(scope.row)" v-if="scope.row.unitStatues == 1">
                  还原
                </el-button> -->
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-circle-plus-outline"
                  @click="unitShow(scope.row)"
                  >单位详情</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </el-row>
        <el-row v-else>
          <el-table
            v-loading="loading"
            id="unitTable"
            :data="agentlist"
            max-height="400"
            :row-style="rowStyle"
          >
            <el-table-column
              label="编号"
              align="center"
              prop="agentid"
              width="100"
            />
            <el-table-column
              label="招标人代表姓名"
              align="center"
              prop="name"
              width="310"
            />
            <el-table-column
              label="专业"
              align="left"
              prop="speciality"
              width="350"
            />
            <el-table-column
              label="类别"
              align="center"
              prop="professionType"
              width="200"
            />
            <el-table-column
              label="是否选择"
              align="center"
              prop="isTick"
              width="150"
            >
              <template slot-scope="scope">
                {{ scope.row.isTick == 1 ? "是" : "否" }}
              </template>
            </el-table-column>
          </el-table>
        </el-row>
      </template>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="extractAdd"
          style="margin-right: 15%; padding: 30px; border-radius: 50px"
          >抽 取</el-button
        >
        <el-button
          type="danger"
          @click="returnApply"
          style="margin-right: 30%; padding: 30px; border-radius: 50px"
          >退 回</el-button
        >
      </div>
    </el-dialog>

    <!-- 抽签过程展示窗口 -->
    <el-dialog
      class="dialog"
      :title="title"
      :visible.sync="dialogVisible"
      width="30%"
      append-to-body
      @close="closeDialog"
      :close-on-click-modal="false"
    >
    <div style="width: 100%;"><span style="text-align: center; margin-left: 20%; color: red;" >单位抽取中，请点击“确定”确认单位</span></div>
    
      <div style="margin-top: 20px; text-align: center;" class="companyInfo" :style="{ color: bgColor }">
        
        {{ currentCompany }}
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 查看项目抽签结果对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="resultOpen"
      width="800px"
      append-to-body
      @close="closeTable"
      :close-on-click-modal="false"
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="120px"
        style="width: 700px; padding-left: 50px"
      >
      <el-row v-if="this.form.randomUnittypeId != 15">
          <table
            class="printTable"
            border="1"
            id="printMe"
            cellspacing="0"
            width="100%"
            height="800px"
          >
            <caption align="top" style="margin-bottom: 30px; font-size: 24px">
              {{
                form.unitTypeName === "施工单位"
                  ? "重庆高新开发建设投资集团有限公司非公招项目施工单位抽选结果表"
                  : "重庆高新开发建设投资集团有限公司中介机构抽取结果表"
              }}
            </caption>
            <tr>
              <td
                colspan="3"
                style="text-align: left"
                height="40px"
                class="font-FangSong topfont noBorder title-font"
              >
                申请单位：{{ form.createBy }}
              </td>
              <td
                colspan="2"
                style="text-align: right"
                class="topfont noBorder font-FangSong"
              >
                日期：{{ form.createTime | dateTime }}
              </td>
            </tr>
            <tr>
              <th rowspan="3" width="80px" class="bigfont">
                项 目 基
                <br />
                本 情 况
              </th>
              <td width="120px" height="60px" class="small font-SimHei">
                项 目 名 称
              </td>
              <th colspan="3" class="input commonBorder font-FangSong">
                {{ form.extractItem }}
              </th>
            </tr>
            <tr>
              <td class="small font-SimHei">建 设 地 址</td>
              <th colspan="3" class="input commonBorder font-FangSong">
                {{ form.extractAddress }}
              </th>
            </tr>
            <tr>
              <td class="small font-SimHei">
                工 程 费 用
                <br />
                (万 元)
              </td>
              <th width="150px" class="input font-FangSong">
                {{ form.extractPrice }}
              </th>
              <td width="80px" class="small font-SimHei">建 设 周 期</td>
              <th class="input commonBorder font-FangSong">
                {{ form.extractPeriod }}
              </th>
            </tr>
            <tr>
              <th
                :rowspan="form.unitTypeName !== '施工单位' ? rowspanList : 4"
                class="bigfont"
              >
                中 标<br />信 息
              </th>
              <td
                class="small font-SimHei"
                v-if="form.unitTypeName !== '施工单位'"
              >
                抽 取 库
              </td>
              <th
                class="input font-FangSong"
                v-if="form.unitTypeName !== '施工单位'"
              >
                {{ form.unitTypeName }}
              </th>
              <td class="small font-SimHei">暂定中介服务费（万元）</td>
              <th colspan="3" class="input commonBorder font-FangSong">
                {{ form.maxPrice }}
              </th>
            </tr>
            <tr v-if="form.unitTypeName !== '施工单位'">
              <td class="small font-SimHei">业 务 类 型</td>
              <th class="input font-FangSong">{{ form.extractBusinessType }}</th>
              <td class="small font-SimHei">抽 取 时 间</td>
              <th class="input commonBorder font-FangSong">
                {{ form.updateTime | dateTime }}
              </th>
            </tr>
            <tr>
              <td
                colspan="4"
                height="60px"
                class="small commonBorder font-SimHei"
              >
                中 标 单 位 列 表
              </td>
            </tr>
            <tr>
              <td height="60px" class="small font-SimHei">序 号</td>
              <td class="small font-SimHei">单 位 名 称</td>
              <td width="120px" class="small font-SimHei">联 系 人</td>
              <td width="120px" class="small commonBorder font-SimHei">
                联 系 电 话
              </td>
            </tr>
            <tr v-if="items == ''">
              <th height="60px"></th>
              <th></th>
              <th></th>
              <th class="commonBorder"></th>
            </tr>
            <tr v-for="(item, index) in items" :key="item.id">
              <th height="60px" class="input font-FangSong">{{ index + 1 }}</th>
              <th class="input font-FangSong">{{ item.randomUnitName }}</th>
              <th class="input font-FangSong">{{ item.randomLinkman }}</th>
              <th class="input commonBorder font-FangSong">
                {{ item.randomPhone }}
              </th>
            </tr>
            <tr>
              <th rowspan="4" class="bigfont a1">
                参 与 抽
                <br />
                取 人 员
              </th>
              <td class="small font-SimHei">抽 取 地 点</td>
              <th class="input commonBorder font-FangSong" colspan="3">
                {{ form.extractPlace }}
              </th>
            </tr>
            <tr>
              <td class="small font-SimHei">现 场 抽 取 人</td>
              <th colspan="3" class="input commonBorder font-FangSong">
                {{ form.extractUser }}
              </th>
            </tr>
            <tr>
              <td rowspan="2" class="small a1 font-SimHei">
                纪 检 监 察
                <br />
                人 员
              </td>
              <th
                colspan="3"
                rowspan="2"
                class="input commonBorder a1 font-FangSong"
              ></th>
            </tr>
          </table>
        </el-row>
        <el-row v-else>
          <table class="table" border="1" cellspacing="0" cellpadding="0" id="printResult" width="100%" height="800px">
              <caption align="top" class="title" style="margin-bottom: 30px; font-size: 24px">
                  重庆高新开发建设投资集团有限公司招标人代表抽取结果表
              </caption>
              <tr>
                  <td class="ceil-first" colspan="4">申请单位：{{ form.createBy }}</td>
                  <td class="ceil-second" colspan="1">日期：{{ form.createTime.substr(0, 10) }}</td>
              </tr>
              <tr>
                  <td rowspan="5" colspan="1" class="left-class" style="width: 100px;">项目基本情况</td>
              </tr>
              <tr>
                  <td rowspan="1" colspan="1" style="width: 100px;">项目名称</td>
                  <td colspan="4">{{ form.extractItem }}</td>
              </tr>
              <tr>
                  <td rowspan="1" colspan="1">业务类型</td>
                  <td colspan="3">{{ form.extractBusinessType }}</td>
              </tr>
              <tr>
                  <td rowspan="1" colspan="1">开标时间</td>
                  <td colspan="3">{{ form.tenderStartTime }}</td>
              </tr>
              <tr>
                  <td rowspan="1" colspan="1">暂定中介服务费（万元）</td>
                  <td colspan="3">{{ form.maxPrice }}</td>
              </tr>
              <tr>
                  <td rowspan="20" colspan="1" class="left-class">抽取信息</td>
              </tr>
              <tr class="centered">
                  <td colspan="4">抽中招标人代表列表</td>
              </tr>
              <tr class="centered" style="text-align: center;">
                  <td class="serial" >序号</td>
                  <td>姓名</td>
                  <td>联系电话</td>
                  <td>所在公司</td>
              </tr>
              <template v-for="(item, index) in items">
                  <tr class="centered">
                      <td rowspan="4" style="text-align: center;">{{index+1}}</td>
                  </tr>
                  <tr class="centered">
                      <td style="width: 100px;">{{item.name}}</td>
                      <td style="width: 200px;">{{item.telphone}}</td>
                      <td>{{item.company}}</td>
                  </tr>
                  <tr class="centered">
                      <td>职称专业</td>
                      <td colspan="2">身份证号</td>
                  </tr>
                  <tr class="centered">
                      <td>{{item.profession}}</td>
                      <td colspan="2">{{item.idcard}}</td>
                  </tr>
              </template>
              <tr>
                  <td>抽取地点</td>
                  <td colspan="3">{{ form.extractPlace }}</td>
              </tr>
              <tr>
                  <td>现场抽取人</td>
                  <td colspan="3">{{ form.extractUser }}</td>
              </tr>
              <tr>
                  <td colspan="4">纪检监察人员:</td>
              </tr>
          </table>
        </el-row>
        
        <el-button
          v-print="'#printMe'"
          type="primary"
          style="margin-top: 10px; margin-left: 90%"
          >打 印</el-button
        >
      </el-form>
    </el-dialog>
    <el-dialog
      :title="title"
      :visible.sync="exclude"
      width="500px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="禁用理由" prop="maxPrice">
          <el-input
            v-model="form.randomBanRansom"
            type="textarea"
            cols="5"
            rows="5"
            placeholder="请输入禁用理由"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="excludeSave">保 存</el-button>
        <el-button @click="call">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      width="30%"
      :visible.sync="innerVisible"
      append-to-body
      class="form-dialog"
    >
      <img :src="form.extractSignUrl" class="form-img-line" />
    </el-dialog>

    <!-- 单位信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="unitopen"
      width="60%"
      append-to-body
    >
      <div class="unitSort-box">
        <unitDetail :formUnit="formUnit"></unitDetail>

        <div
          class="on-going-project"
          v-if="
            unitDetailRow.unitStatues == 2 || unitDetailRow.unitStatues == 3
          "
        >
          <div>进行中的项目</div>

          <div class="going-project-table">
            <el-table :data="onGoingProject" border style="width: 100%">
              <el-table-column
                prop="index"
                label="序号"
                width="180"
                align="center"
              >
              </el-table-column>
              <el-table-column
                prop="extractItem"
                label="项目名称"
                align="center"
              >
              </el-table-column>
              <el-table-column
                prop="extractPrice"
                align="center"
                label="工程费用（万元）"
              >
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormUnit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listExtract,
  getExtract,
  updateExtract,
  exportExtract,
  getLists,
  sureExtract,
} from "@/api/unit/extract";
import {
  listRandom,
  delRandom,
  addRandom,
  DeleteMapping,
  getRandomresult,
  getAgentInfo,
} from "@/api/unit/random";
import { randomlist, getUnit, getGoingUnit, getRandomList,agentlist } from "@/api/unit/unit";
import { listUser } from "@/api/system/user";
import { listUnittype } from "@/api/unit/unittype";
import quotationConfirm from "../../../common/operation/quotationConfirm";

import { createColor } from "foreign-country-utils";

import unitDetail from "@/common/unitDetail/unitDetail";
export default {
  name: "RandomRandom",
  components: {
    quotationConfirm,
    unitDetail,
  },
  data() {
    return {
      unitDetailRow: {},
      //控制资质列隐藏显示
      showmake: true,
      //打开预览
      innerVisible: false,
      currentRow: {},
      quotationConfirm: [], //傳給quotationConfirm展示的數據
      price: [], //傳給quotationConfirm展示的數據
      //动态控制rowspan
      rowspanList: 5,
      //循环表格数组
      items: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      //保存禁用理由
      exclude: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目申请表格数据
      extractList: [],
      // 单位信息表格数据
      unitList: [],
      //招标招标人代表表格数据
      agentlist: [],
      //抽取单位库id
      unittype: "",
      // 单位抽签表格数据
      randomList: [],
      //抽签结果表格数据
      randomResultList: [],
      // 排除项目集合
      RandomList: [],
      // 单位类型字典
      unitTypeOptions: [],
      //抽取人单位字典
      unitTypeponsonOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //抽取弹出层
      extractOpen: false,
      unitopen: false,
      //项目抽签结果层
      resultOpen: false,
      //按钮配置
      value1: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        extractItem: null,
        extractUser: null,
        createBy: null,
        extractApproveStatus: null,
        randomUnittypeId: null,
        unitTypeId: null,
      },
      UnitqueryParams: {
        pageNum: 1,
        pageSize: 10,
        unitName: null,
        unitNaturalGrade: null,
        unitNaturalScope: null,
        unitType: null,
      },
      // 查询参数
      RandomqueryParams: {
        pageNum: 1,
        pageSize: 10,
        extractId: null,
        randomUnitId: null,
        randomBan: "0",
      },
      // 查询抽签结果参数
      resultqueryParams: {
        extractId: null,
      },
      // 表单参数
      form: {
        extractBusinessType: "",
        extractNumber: null,
      },
      //单位详情
      formUnit: {},
      ruleForm: {
        extractUser: "",
        extractPlace: "",
        quoteLimitTime: "",
      },
      completeForm: {
        extractId: "",
        extractApproveStatus: "",
        extractNumber: "",
      },
      userRules: {
        extractUser: [
          { required: true, message: "抽取人不能为空", trigger: "blur" },
        ],
        extractPlace: [
          { required: true, message: "抽取地点不能为空", trigger: "blur" },
        ],
        quoteLimitTime: [
          { required: true, message: "报价限制时间不能为空", trigger: "blur" },
        ],
      },
      // 表单校验
      rules: {
        extractUser: [
          { required: true, message: "抽取人不能为空", trigger: "blur" },
        ],
        extractItem: [
          { required: true, message: "项目名称不能为空", trigger: "blur" },
        ],
        unitTypeName: [
          { required: true, message: "抽取库不能为空", trigger: "change" },
        ],
        extractPlace: [
          { required: true, message: "抽取地点不能为空", trigger: "change" },
        ],
        quoteLimitTime: [
          {
            required: true,
            message: "报价限制时间不能为空",
            trigger: "change",
          },
        ],
      },
      dialogVisible: false,
      currentCompany: [],
      isStart: true,
      timer: 0,
      bgColor: "",
      onGoingProject: [],
    };
  },
  created() {
    this.rowspanList = 5;
    this.getList();
    listUnittype(this.unitTypeParams).then((response) => {
      this.unitTypeOptions = response.rows;
    });
    listUser().then((response) => {
      this.unitTypeponsonOptions = response.rows;
    });
  },
  methods: {
    //抽取人单位
    UnitTypeChangepenson(value) {
      listUser().then((response) => {
        for (var o = 0; o < response.rows.length; o++) {
          if (value == response.rows[o].userId) {
            this.queryParams.createBy = response.rows[o].nickName;
          }
        }
      });
    },
    // 改变页码显示不同的数据
    currentChange(page) {
      this.pageNum = page;
      this.loadExtractList(this.pageNum);
    },
    /** 查询项目申请列表 */
    getList() {
      this.loading = true;
      this.queryParams.extractApproveStatus = "2,4";
      this.queryParams.unitTypeId = "15";
      listExtract(this.queryParams).then((response) => {
        this.extractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    //为排除的单位添加颜色区分
    tableRowClassName({ row, rowIndex }) {
      if (row.unitStatues === 1) {
        return "denger-row";
      } else if (row.unitStatues === 2) {
        return "denger-row";
      } else if (row.unitStatues === 3) {
        return "denger-row";
      }
      return "";
    },
    // 表单重置
    reset() {
      this.form = {
        extractId: null,
        extractItem: null,
        extractUser: null,

        extractRemarks: null,
        extractBanReason: null,
        extractScore: null,
        extractApproveStatus: "1",
        randomUnittypeId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        RandomList: [],
        extractPlace: null,
        quoteLimitTime: null,
        unitTypeName: null,
      };
      this.resetForm("form");
    },
    //单位详情表单重置
    resetUnit() {
      this.formUnit = {
        unitId: null,
        unitSort: null,
        unitType: null,
        unitName: null,
        unitNaturalGrade: null,
        unitNaturalScope: null,
        unitAddress: null,
        unitRemarks: null,
      };
    },
    //转换单位库类型
    selecttypeLabel(datas, value) {
      var actions = [];
      Object.keys(datas).some((key) => {
        if (datas[key].unittypeId == "" + value) {
          actions.push(datas[key].unittypeName);
          return true;
        }
      });
      return actions.join("");
    },
    approveStatusFormat(row, column) {
      return this.getType(row, column);
    },
    //手动排除翻译状态
    ManualApproveStatusFormat(row, column) {
      if (row.unitStatues == 0) {
        return "否";
      } else if (row.unitStatues == 1) {
        return "是";
      } else if (row.unitStatues == 2) {
        return "否";
      } else if (row.unitStatues == 3) {
        return "否";
      } else if (row.randomBan == 4) {
        return "未中标";
      } else if (row.randomBan == 5) {
        return "废除报价";
      }
    },
    //自动排除翻译状态
    AutomaticApproveStatusFormat(row, column) {
      if (row.isTick == 0) {
        return "否";
      } else if (row.isTick == 1) {
        return "是";
      }
    },
    /** 搜索按钮操作 */
    async handleQuery() {
      this.loading = true;
      this.queryParams.pageNum = 1;
      this.queryParams.extractItem = this.queryParams.extractItem;
      this.queryParams.extractApproveStatus = "2,4";
      await getLists(this.queryParams).then((response) => {
        this.extractList = response.rows;
        this.loading = false;
      });
    },
    //单位选择select改变方法
    UnitTypeChange(value) {
      this.queryParams.randomUnittypeId = value;
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.reset();
      this.getList();
    },
    //抽取动画取消
    gifcancel() {
      this.extractOpen = false;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.extractId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 点击当前行
    currentRowChange(currentRow) {
      // console.log(currentRow);
      this.currentRow = currentRow;
      if (this.currentRow !== null) {
        this.quotationConfirm = [
          {
            name: "申请单位",
            detailInfo: currentRow.createBy,
            showTwo: true,
          },
          {
            name: "项目名称",
            detailInfo: currentRow.extractItem,
            showTwo: true,
          },
          {
            name: "建设地址",
            detailInfo: currentRow.extractAddress,
            showTwo: true,
          },
          {
            name: "建设周期",
            detailInfo: currentRow.extractPeriod,
            showTwo: true,
          },
          {
            name: "工程费用（万元）",
            detailInfo: currentRow.extractPrice,
            showTwo: true,
          },
          {
            name: "工程概况",
            detailInfo: currentRow.projectOverview,
            showTwo: true,
          },
          {
            name: "中介机构服务费（万元）",
            detailInfo: currentRow.maxPrice,
            showTwo: true,
          },
          {
            name: "抽取要求",
            detailInfo: currentRow.extractBanReason, //不确定
            showTwo: true,
          },
          {
            name: "抽  取  库",
            detailInfo: currentRow.unitTypeName,
            showTwo: true,
          },
          {
            name: "经办人",
            detailInfo: currentRow.extractCharge,
            showTwo: true,
          },
          {
            name: "联系电话",
            detailInfo: currentRow.extractPhone,
            showTwo: true,
          },
          {
            name: "业务类型",
            detailInfo: currentRow.extractBusinessType,
            showTwo: true,
          },
          {
            name: "签字表",
            detailInfo: currentRow.extractSignUrl,
            showimg: true,
            showTwo: true,
          },
          {
            name: "是否需要驻场服务",
            detailInfo: currentRow.extractResident == 0 ? "是" : "否",
            showTwo: false,
          },
          {
            name: "驻场服务人数(至少)",
            detailInfo:
              currentRow.extractResident == 0
                ? currentRow.extractResidentNumber
                : "",
            showTwo: true,
          },
          {
            name: "完成时限",
            detailInfo:
              currentRow.extractResident == 0
                ? currentRow.extractLimitedTime
                : "",
            showTwo: true,
          },
          {
            name: "驻 场 要 求",
            detailInfo:
              currentRow.extractResident == 0
                ? currentRow.extractStationRequire
                : "",
            showTwo: false,
          },
          {
            name: "抽取单位数",
            detailInfo: currentRow.extractNumber,
            showTwo: false,
          },
        ];
      }
    },

    // 点击抽取按钮
    extractAdd() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          this.dialogVisible = true;
          this.isStart = true;
          this.timer = setInterval(() => {
            const index = Math.floor(Math.random() * 100+1 );
            this.currentCompany = index;
            this.bgColor = createColor();
          }, 50);
        }
      });
    },
    //点击退回按钮
    returnApply() {
      var that = this;
      this.$confirm("是否确定退回?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          that.form.extractApproveStatus = 0;
          updateExtract(that.form).then((response) => {
            that.msgSuccess("退回成功");
            that.open = false;
            //console.log(this.form.RandomList);
            that.getList();
          });
        })
        .catch(() => {
          this.getList();
        });
    },

    // 停止定时器
    stop() {
      clearInterval(this.timer);
      this.isStart = false;
    },

    // 点击确认按钮
    async confirm() {
      this.completeForm.extractNumber = this.form.extractNumber;
      clearInterval(this.timer);
      // 将抽中单位数据传给后端
      const randomUnittypeId = this.currentRow.randomUnittypeId;
      const extractId = this.currentRow.extractId;
      const res1 = await addRandom({ randomUnittypeId, extractId });
      this.ruleForm.extractId = this.currentRow.extractId;
      this.ruleForm.extractApproveStatus = "4";
      //const res2 = await addExtract({ extractId });
      const res3 = await updateExtract(this.ruleForm);
      // const res2 = await addExtract({ extractId });
      this.dialogVisible = false;
      this.$message.success("抽取成功");
      this.open = false;
      this.rowspanList = this.form.extractNumber + 4;
      //打开结果展示窗口
      var row = {
        extractId: null,
      };
      row.extractId = this.currentRow.extractId;
      //this.resultShow(row);
      //const extractId = row.extractId || this.ids;
      this.RandomqueryParams.extractId = extractId;
      if (this.form.extractNumber <= 1) {
        this.RandomqueryParams.randomBan = "3";
      } else {
        this.RandomqueryParams.randomBan = "2";
      }
      if(randomUnittypeId==15){
        await getAgentInfo({ extractId}).then((response) => {
            this.items = response.rows;
            console.log(response.rows);
            if (this.items.length < 2) {
              this.rowspanList == 5;
            } else {
              this.rowspanList = this.items.length + 5;
            }
        });
      }else{
        listRandom(this.RandomqueryParams).then((response) => {
          console.log(response);
          this.items = response.rows;
        });
      }
      
      
      getExtract(extractId).then((response) => {
        this.form = response.data;
        this.resultOpen = true;
        this.title = "";
      });
      this.getList();
    },
    // 关闭弹窗
    closeDialog() {
      clearInterval(this.timer);
    },
    // 关闭打印表
    closeTable() {
      this.rowspanList = 5;
      this.reset();
      this.getList();
    },
    closeTablebig() {
      this.reset();
      this.getList();
    },
    /** 单位详情 */
    unitShow(row) {
      this.unitDetailRow = row;
	  console.log(row);
      const unitId = row.unitId || this.ids;
      getUnit(unitId).then((response) => {
        this.formUnit = response.data;
        this.unitopen = true;
        this.title = "单位详情";
      });
      getGoingUnit({ unitId }).then((res) => {
        this.onGoingProject = res.rows;
        this.onGoingProject.forEach((item, index) => {
          item.index = index + 1;
        });
      });
    },
    /** 抽签按钮操作 */
    handleUpdate(row) {
      if (
        row.randomUnittypeId == 1 ||
        row.randomUnittypeId == 3 ||
        row.randomUnittypeId == 4 ||
        row.randomUnittypeId == 9
      ) {
        this.showmake = false;
      } else {
        this.showmake = true;
      }
      if (row.extractApproveStatus > 2) {
        this.msgSuccess("该项目已抽签，不可重复抽取");
        return;
      }
      this.reset();
      const extractId = row.extractId || this.ids;
      getExtract(extractId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "项目单位抽签";
      });
      this.UnitqueryParams.extractId = parseInt(row.extractId);
      //查询单位table数据
      this.UnitqueryParams.unitType = row.randomUnittypeId;
      this.unittype = row.randomUnittypeId;
      if(row.randomUnittypeId == 15){
        agentlist(this.UnitqueryParams).then((response) => {
          this.agentlist = response.rows;
          this.loading = false;
        });
      }else{
        getRandomList(this.UnitqueryParams).then((response) => {
          this.unitList = response.rows;
          this.loading = false;
        });
      }
      
    },
    /**还原按钮*/
    DeleteMappingBtn(row) {
      var _this = this;
      const unitId = row.unitId || this.ids;
      //获取项目id
      this.RandomqueryParams.extractId = this.form.extractId;
      //获取单位id
      this.RandomqueryParams.randomUnitId = unitId;
      //console.log(this.RandomqueryParams.randomUnitId);
      this.$confirm("是否需要复原?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          //判断当前是否有存储好的排除数据
          //刷新单位库下的单位列表状态
          for (var i = 0; i < _this.unitList.length; i++) {
            if (_this.unitList[i].unitId == row.unitId) {
              _this.unitList[i].unitStatues = null;
            }
          }
          return DeleteMapping(_this.RandomqueryParams);
        })
        .then(() => {
          this.msgSuccess("还原成功");
          //刷新表格
          this.UnitqueryParams.unitType = this.form.randomUnittypeId;
          this.UnitqueryParams.extractId = parseInt(this.form.extractId);
          //console.log('extractId' + this.UnitqueryParams.extractId);
          getRandomList(this.UnitqueryParams).then((response) => {
            this.unitList = response.rows;
            this.loading = false;
          });
        }),
        () => {};
    },
    /** 查看抽签结果按钮 */
    async resultShow(row) {
      const extractId = row.extractId || this.ids;
      this.resultqueryParams.extractId = extractId.toString();
      if(row.randomUnittypeId == 15){
        await getAgentInfo(this.resultqueryParams).then((response) => {
          this.items = response.rows;
          console.log(response.rows);
          if (this.items.length < 2) {
            this.rowspanList == 5;
          } else {
            this.rowspanList = this.items.length + 4;
          }
        });
      }else{
        await getRandomresult(this.resultqueryParams).then((response) => {
          this.items = response.data;
          if (this.items.length < 2) {
            this.rowspanList == 5;
          } else {
            this.rowspanList = this.items.length + 4;
          }
        });
      }
      
      await getExtract(extractId).then((response) => {
        this.form = response.data;
        this.resultOpen = true;
        this.title = "";
      });
    },
    //禁用按钮
    overcome(row) {
      this.unitId = row.unitId || this.ids;
      this.unittype = row.unitType || this.ids;
      this.unitName = row.unitName || this.ids;
      this.exclude = true;
      this.title = "禁用单位";
    },
    //抽取完成按钮
    extractionComplete(row) {
      var that = this;
      this.$confirm("是否抽取完成", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(function () {
        that.completeForm.extractId = row.extractId || that.ids;
        that.completeForm.extractApproveStatus = 7;
        that.completeForm.extractNumber = row.extractNumber;
        console.log(that.form.extractNumber);
        console.log(that.completeForm.extractNumber);
        sureExtract(that.completeForm).then((response) => {
          that.getList();
          that.msgSuccess("抽取完成");
        });
      });
    },
    //禁用取消
    call() {
      this._data.exclude = false;
    },
    submitFormUnit() {
      this.unitopen = false;
      this.resetUnit();
    },
    excludeSave() {
      //创建一个禁用实体类
      var RandomNew = {
        randomUnittypeId: null,
        randomBanRansom: null,
        randomUnitId: null,
        randomUnitName: null,
        extractId: null,
      };
      RandomNew.randomUnittypeId = this.unittype;
      RandomNew.randomUnitId = this.unitId;
      RandomNew.extractId = this.form.extractId;
      //表单区一样的名字
      RandomNew.randomBanRansom = this.form.randomBanRansom;
      RandomNew.randomUnitName = this.unitName;
      this.RandomList.push(RandomNew);
      this.exclude = false;
      //刷新单位库下的单位列表状态
      for (var i = 0; i < this.unitList.length; i++) {
        if (this.unitList[i].unitId == RandomNew.randomUnitId) {
          this.unitList[i].unitStatues = 1;
        }
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.extractOpen = false;
          this.form.extractApproveStatus = 3;
          if (this.form.extractId != null) {
            updateExtract(this.form).then((response) => {
              this.getList();
            });
            addRandom(this.form).then((response) => {
              this.reset();
              this.open = false;
              this.msgSuccess("抽取成功");
            });
          } else {
          }
        }
      });
    },

    /** 重置结果按钮操作 */
    reback(row) {
      const extractIds = row.extractId || this.ids;
      var that = this;
      console.log(extractIds);
      this.$confirm("是否重置当前抽签结果", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          delRandom(extractIds)
            .then((res) => {
              console.log("重置成功", res);
              that.$message({
                message: res.msg,
                type: "success",
              });
              that.getList();
            })
            .catch((err) => {
              console.log("err", err);
            });
        })
        .catch(() => {
          console.log("取消");
          this.getList();
        });
      this.ruleForm.extractPlace = "";
      this.ruleForm.extractUser = "";
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有项目申请数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportExtract(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
    rowStyle({ row }) {
      let style = {};
      if (row.isTick == 0 || row.notWonReason) style.backgroundColor = "#ffe4e1";
      return style;
    }
  },
  filters: {
    dateTime(val) {
      if (val) {
        return val.substr(0, 10);
      }
    },
  },
};
</script>
<style lang="scss" scoped>

.commonWidth {
  width: 300px;
}
::v-deep .el-form {
  padding: 10px;
  margin-bottom: 10px;
}
::v-deep .el-dialog__body {
  text-align: center;
}
::v-deep .el-table .cell {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
::v-deep .el-table .cell:hover {
  white-space: normal;
}
.topfont {
  font-size: 16px;
  font-weight: 400;
}
.small {
  text-align: center;
  font-weight: 100;
  font-size: 16px;
}
.bigfont {
  font-size: 18px;
  font-weight: 100;
  text-align: center;
  font-family: FangSong;
}
.input {
  font-size: 16px;
  font-weight: 400;
}
::v-deep .el-table .denger-row {
  background: #ffe4e1;
}
::v-deep .el-date-editor {
  margin-left: -4px;
}
.printTable {
  border: unset;
}
.noBorder {
  border: unset;
}
.commonBorder {
  border-right: 1px solid #9a9a9a;
}
.a1 {
  border-bottom: 1px solid #9a9a9a;
}
.title-font {
  font-family: FangSong;
}
.font-SimHei {
  font-family: FangSong;
}
.font-FangSong {
  font-family: FangSong;
}
.unitSort-box {
  text-align: left;
}
.unitSort-box li {
  margin-top: 5px;
}
.form-img-out {
  width: 130px;
  height: 130px;
}
.form-img-line {
  width: 500px;
  height: 500px;
}
.form-dialog {
  text-align: center;
}
.on-going-project {
  font-size: 18px;
  color: #303133;
  padding-left: 10px;
}
.going-project-table {
  padding: 20px 30px;
}
::v-deep[data-v-04b6f7de] .el-dialog__body {
  text-align: left;
}
</style>
